package com.clk.portfoy.classlib.piyasa;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.clk.portfoy.engines.WebEngine;

public class Piyasa {
	private double xu100 = 0;
	private double dolarTL = 0;
	private double euroTL = 0;
	private double altinTL = 0;
	private double petrol = 0;
	private double bono = 0;
	private Date refreshDate;
	private List<InfPiyasaObserver> observer = new ArrayList<InfPiyasaObserver>();

	// ---------------------------------------------------------------------------------
	public double getXu100() {
		return xu100;
	}

	// ---------------------------------------------------------------------------------
	public void setXu100(double xu100) {
		this.xu100 = xu100;
	}

	// ---------------------------------------------------------------------------------
	public double getDolarTL() {
		return dolarTL;
	}

	// ---------------------------------------------------------------------------------
	public void setDolarTL(double dolarTL) {
		this.dolarTL = dolarTL;
	}

	// ---------------------------------------------------------------------------------
	public double getEuroTL() {
		return euroTL;
	}

	// ---------------------------------------------------------------------------------
	public void setEuroTL(double euroTL) {
		this.euroTL = euroTL;
	}

	// ---------------------------------------------------------------------------------
	public double getAltinTL() {
		return altinTL;
	}

	// ---------------------------------------------------------------------------------
	public void setAltinTL(double altinTL) {
		this.altinTL = altinTL;
	}

	// ---------------------------------------------------------------------------------
	public double getPetrol() {
		return petrol;
	}

	// ---------------------------------------------------------------------------------
	public void setPetrol(double petrol) {
		this.petrol = petrol;
	}

	// ---------------------------------------------------------------------------------
	public double getBono() {
		return bono;
	}

	// ---------------------------------------------------------------------------------
	public void setBono(double bono) {
		this.bono = bono;
	}

	// ---------------------------------------------------------------------------------
	public Date getRefreshDate() {
		return refreshDate;
	}

	// ---------------------------------------------------------------------------------
	public void refresh() {
		try {
			WebEngine.fiilPiyasaValues(this);
			this.refreshDate = new Date();
			System.out.println("***********************************************************************");
			notifyObs();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	// ---------------------------------------------------------------------------------
	public void register(InfPiyasaObserver obs) {
		if (!observer.contains(obs)) {
			observer.add(obs);
		}
	}

	// ---------------------------------------------------------------------------------
	public void unRegister(InfPiyasaObserver obs) {
		observer.remove(obs);
	}

	// ---------------------------------------------------------------------------------
	private void notifyObs() {
		for (int i = 0; i < observer.size(); i++) {
			observer.get(i).notifyObs(this);
		}
	}
	// ---------------------------------------------------------------------------------
}
